const app = getApp()
Component({
  properties: {
    types: {
      type: String,
      value: ''
    },
    title: {
      type: String,
      value: ''
    },
    message: {
      type: String,
      value: ''
    },
    //中间弹框图片
    showMiddleModalImg: {
      type: String,
      value: ''
    },
    list: {
      type: Array,
      value: []
    },
    showTitle: {
      type: Boolean,
      value: false
    }
  },

  data: {
    isShowModal: false,
    selectDate: '',
    selectDateFormat: '',
    selectTab: 'date',
    value: [12, 0],
    times: [
      '00',
      '01',
      '02',
      '03',
      '04',
      '05',
      '06',
      '07',
      '08',
      '09',
      '10',
      '11',
      '12',
      '13',
      '14',
      '15',
      '16',
      '17',
      '18',
      '19',
      '20',
      '21',
      '22',
      '23'
    ],
    time: '12',
    branchs: [
      '00',
      '01',
      '02',
      '03',
      '04',
      '05',
      '06',
      '07',
      '08',
      '09',
      '10',
      '11',
      '12',
      '13',
      '14',
      '15',
      '16',
      '17',
      '18',
      '19',
      '20',
      '21',
      '22',
      '23',
      '24',
      '25',
      '26',
      '27',
      '28',
      '29',
      '30',
      '31',
      '32',
      '33',
      '34',
      '35',
      '36',
      '37',
      '38',
      '39',
      '40',
      '41',
      '42',
      '43',
      '44',
      '45',
      '46',
      '47',
      '48',
      '49',
      '50',
      '51',
      '52',
      '53',
      '54',
      '55',
      '56',
      '57',
      '58',
      '59'
    ],
    branch: '00'
  },

  created() {},

  methods: {
    bindChange(item) {
      console.log(item)
      this.setData({
        time: this.data.times[
          item.detail.value[0]
        ],
        branch: this.data.branchs[
          item.detail.value[1]
        ],
        value: [
          item.detail.value[0],
          item.detail.value[1]
        ]
      })
    },
    /**
     * 切换日期和时间切换
     */
    changeTab(item) {
      console.log(item)
      this.setData({
        selectTab:
          item.currentTarget.dataset.tabname
      })
    },
    /**
     * 选择时间
     * @param {*} item
     */
    selectDay(item) {
      if (
        item.detail == null ||
        item.detail == undefined
      ) {
        this.setData({
          selectDate:
            item.year +
            '-' +
            (item.month < 10
              ? '0' + item.month
              : item.month) +
            '-' +
            (item.day < 10
              ? '0' + item.day
              : item.day)
        })
      } else {
        this.setData({
          selectDate:
            item.detail.year +
            '-' +
            (item.detail.month < 10
              ? '0' + item.detail.month
              : item.detail.month) +
            '-' +
            (item.detail.day < 10
              ? '0' + item.detail.day
              : item.detail.day)
        })
      }
      this.setData({
        selectDateFormat: this.data.selectDate.replace(
          /-/g,
          '/'
        )
      })
    },
    clickTest() {},
    //点击确定
    onClickConfirm() {
      const data = this.data
      this.triggerEvent('onConfirm', data)
      //return
      this.onClickHideModal()
    },
    onClickShowModal() {
      if (app.globalData.showModel) {
        return
      }
      app.globalData.showModel = true
      this.setData({
        isShowModal: true
      })
    },
    onClickHideModal() {
      this.setData({
        isShowModal: false
      })
      app.globalData.showModel = false
    }
  }
})
